package com.firefly.dao.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.integration.redis.util.RedisLockRegistry;

import java.time.Duration;
/**
 * @description: 分布式锁
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2023/5/12
 **/
@Configuration
public class RedisLockConfig {
    private static final String LOCK_REGISTRY_REDIS_KEY = "FF_REDIS_LOCK_KEY";
    private static final Duration RELEASE_TIME_DURATION = Duration.ofSeconds(30);

    @Bean
    public RedisLockRegistry lockRegistry(RedisConnectionFactory redisConnectionFactory) {
        return new RedisLockRegistry(redisConnectionFactory, LOCK_REGISTRY_REDIS_KEY,
                RELEASE_TIME_DURATION.toMillis());
    }
}
